home *** CD-ROM | disk | FTP | other *** search
/ Amiga Desktop Video CD / Amiga DeskTop Video CD.iso / install / forceicon / source / rendezvous.h < prev    next >
C/C++ Source or Header  |  1994-06-23  |  3KB  |  151 lines

  1.  
  2. /**********************************************************************/
  3. /*                Try to find Semaphore or create it                  */
  4. /**********************************************************************/
  5. static struct FIconSema *FindFIconSema(void)
  6. {
  7.     struct    FIconSema    *FIconSema;
  8.  
  9.  
  10.         // Semaphore already created ???
  11.  
  12.     Forbid();
  13.     if((FIconSema = (struct FIconSema *)FindSemaphore("ForceIcon rendezvous")))
  14.     {
  15.             // Already launched ???
  16.  
  17. #ifndef PREFSRUN
  18.         if(!FIconSema->ServerTask)
  19.             FIconSema->ServerTask    = FindTask(NULL);
  20.         else
  21.         {
  22.             DisplayError(ERR_NO_RELAUNCH, NULL);
  23.             Signal(FIconSema->ServerTask, SIGBREAKF_CTRL_C);
  24.             FIconSema    = NULL;
  25.         }
  26. #endif
  27.  
  28.         if(FIconSema)
  29.         {
  30.                 // One user more
  31.  
  32.             FIconSema->UseCount++;
  33.         }
  34.  
  35.         Permit();
  36.     }
  37.     else
  38.     {
  39.         if((FIconSema = AllocVec(sizeof(struct FIconSema), MEMF_CLEAR | MEMF_PUBLIC)))
  40.         {
  41.                 // Try to create pool
  42.  
  43.             if((FIconSema->FIconPool = AsmCreatePool(MEMF_CLEAR | MEMF_PUBLIC, 4096, 2048, SysBase)))
  44.             {
  45.                     // Copy name of semaphore
  46.  
  47.                 strcpy(FIconSema->Name, "ForceIcon rendezvous");
  48.  
  49.                     // Set up semaphore
  50.  
  51.                 FIconSema->FIconSema.ss_Link.ln_Name    = FIconSema->Name;
  52.                 FIconSema->UseCount            = 1;
  53.  
  54.  
  55.                     // Add semaphore to list of public semaphores
  56.  
  57.                 AddSemaphore(&FIconSema->FIconSema);
  58.  
  59.                     // Add address of calling task
  60.  
  61. #ifndef PREFSRUN
  62.                 FIconSema->ServerTask            = FindTask(NULL);
  63. #endif
  64.  
  65.                     // Initialize VolumeList
  66.  
  67.                 NewList(&FIconSema->VolumeList);
  68.  
  69.                     // Load in preferences
  70.  
  71.                 ObtainSemaphore(&FIconSema->FIconSema);
  72.                 Permit();
  73.                 LoadPrefs(FIconSema);
  74.                 ReleaseSemaphore(&FIconSema->FIconSema);
  75.                 Forbid();
  76.             }
  77.             else
  78.             {
  79.                 FreeVec(FIconSema);
  80.                 FIconSema = NULL;
  81.             }
  82.         }
  83.  
  84.             // Display error on failure
  85.  
  86.         if(!FIconSema)
  87.             DisplayError(ERR_NOMEM, NULL);
  88.  
  89.         Permit();
  90.     }
  91.  
  92.     return(FIconSema);
  93. }
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. /**********************************************************************/
  104. /*                    Release/remove FIconSemaphore                   */
  105. /**********************************************************************/
  106. static void RemoveFIconSema(struct FIconSema *FIconSema)
  107. {
  108.     if(FIconSema)
  109.     {
  110.             // Remove Semaphore from memory, or simply "log" out ???
  111.  
  112.         ObtainSemaphore(&FIconSema->FIconSema);
  113.         Forbid();
  114.         ReleaseSemaphore(&FIconSema->FIconSema);
  115.  
  116.  
  117.             // We`re no longer available
  118.  
  119. #ifndef PREFSRUN
  120.         FIconSema->ServerTask    = NULL;
  121. #endif
  122.  
  123.  
  124.             // Semaphore still in use ???
  125.  
  126.         if(!--FIconSema->UseCount)
  127.         {
  128.             if(FIconSema->FIconPool)
  129.             {
  130.                     // Free list of patches
  131.  
  132.                 FreeDevVolList(&FIconSema->VolumeList);
  133.  
  134.                     // Remove Pool
  135.  
  136.                 AsmDeletePool(FIconSema->FIconPool, SysBase);
  137.             }
  138.  
  139.                 // Remove Semaphore
  140.  
  141.             RemSemaphore(&FIconSema->FIconSema);
  142.  
  143.                 // Free memory associated
  144.  
  145.             FreeVec(FIconSema);
  146.         }
  147.  
  148.         Permit();
  149.     }
  150. }
  151.